"use strict";

module.exports = (app) => {
  const { STRING, INTEGER, BOOLEAN, DATE, TEXT } = app.Sequelize;

  const Brand = app.model.define("brand", {
    id: {
      type: INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    name: {
      type: STRING(50),
      allowNull: false,
      comment: "品牌名称",
    },
    logo: {
      type: STRING(255),
      comment: "品牌Logo",
    },
    description: {
      type: TEXT,
      comment: "品牌描述",
    },
    website: {
      type: STRING(255),
      comment: "品牌官网",
    },
    sort_order: {
      type: INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: "排序",
    },
    is_show: {
      type: BOOLEAN,
      allowNull: false,
      defaultValue: true,
      comment: "是否显示",
    },
    created_at: DATE,
    updated_at: DATE,
  });

  // 关联关系
  Brand.associate = function () {
    // 品牌与商品：一对多关系
    app.model.Brand.hasMany(app.model.Product, { foreignKey: "brand_id" });
  };

  return Brand;
};
